package com.lyc.iotdb.controller;

import com.lyc.iotdb.common.iot.IotdbSessionConfig;
import com.lyc.iotdb.common.utils.Rst;
import com.lyc.iotdb.entity.WeatherEntity;
import com.lyc.iotdb.service.WeatherService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 天气信息Controller
 *
 * @author kit
 */
@RestController
public class WeatherController {

    @Resource
    private IotdbSessionConfig iotdbSessionConfig;

    @Resource
    private WeatherService weatherService;

    /**
     * 插入数据
     *
     * @param weather 数据
     * @return rst
     */
    @PostMapping("save")
    public Rst save(@RequestBody WeatherEntity weather) {
        return weatherService.save(weather);
    }

    /**
     * 批量插入数据
     *
     * @param list 批量数据
     * @return rst
     */
    @PostMapping("batchSave")
    public Rst batchSave(@RequestBody List<WeatherEntity> list) {
        iotdbSessionConfig.insertRecords(list);
        return Rst.ok();
    }

    /**
     * 分页获取数据
     *
     * @param params 查询参数
     * @return rst
     */
    @GetMapping("getPageList")
    public Rst getPageList(@RequestParam Map<String, Object> params) {
        return Rst.data(weatherService.getPageList(params));
    }

    /**
     * 分页查询（Map)
     *
     * @return rst
     */
    @GetMapping("getPageMap")
    public Rst getPageMap(@RequestParam Map<String, Object> params) {
        return Rst.data(weatherService.getPageMap(params));
    }

    /**
     * 删除
     *
     * @param params startTime,endTime yyyy-MM-dd HH:mm:ss
     * @return rst
     */
    @GetMapping("delete")
    public Rst delete(@RequestParam Map<String, Object> params) {
        return weatherService.delete(params);
    }
}
